package com.dnjn.happiness.biz.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dnjn.happiness.biz.domain.AdviceThumbsUp;
import com.dnjn.happiness.biz.mapper.AdviceThumbsUpMapper;
import com.dnjn.happiness.biz.service.IAdviceService;
import com.dnjn.happiness.biz.service.IAdviceThumbsUpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 点赞 服务实现类
 * </p>
 *
 * @author Amber
 * @since 2023-10-04
 */
@Service
public class AdviceThumbsUpServiceImpl extends ServiceImpl<AdviceThumbsUpMapper, AdviceThumbsUp> implements IAdviceThumbsUpService {

    @Autowired
    AdviceThumbsUpMapper adviceThumbsUpMapper;
    @Autowired
    IAdviceService adviceService;

    @Override
    @Transactional
    public int saveThumps(AdviceThumbsUp adviceThumbsUp) {
        int i = adviceThumbsUpMapper.insert(adviceThumbsUp);
        if (i > 0) {//如果点赞了
            Long adviceId = adviceThumbsUp.getAdviceId();
            Long thumsCount = adviceThumbsUp.getThumsCount();
            return adviceService.updateAdviceById(adviceId, thumsCount);
//            return i;
        }
        return i;
    }

}
